Skip to content

Fix wallet name generation to use explicit public descriptor checksum#482

Open
AmosOO7 wants to merge 3 commits into
bitcoindevkit:masterfrom
AmosOO7:add_check_for_descriptors-wallet_name_from_descriptor
Open

Fix wallet name generation to use explicit public descriptor checksum#482
AmosOO7 wants to merge 3 commits into
bitcoindevkit:masterfrom
AmosOO7:add_check_for_descriptors-wallet_name_from_descriptor

Conversation

@AmosOO7
Copy link
Copy Markdown
Contributor

@AmosOO7 AmosOO7 commented May 11, 2026

Summary

  • Update wallet_name_from_descriptor to compute checksum directly from parsed public descriptor strings
  • Remove reliance on to_string() implicitly containing #checksum
  • Clarify in docs that wallet names are defined by public descriptor checksums
  • Add regression coverage for equivalent xpub/xprv descriptors producing the same wallet name

Testing

cargo test test_wallet_name_from_descriptor_public_key_check

Checklists

All Submissions:

Closes #481

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.91%. Comparing base (6dca318) to head (21a0d4d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #482      +/-   ##
==========================================
+ Coverage   80.55%   80.91%   +0.35%     
==========================================
  Files          24       24              
  Lines        5472     5469       -3     
  Branches      243      244       +1     
==========================================
+ Hits         4408     4425      +17     
+ Misses        987      967      -20     
  Partials       77       77              
Flag Coverage Δ
rust 80.91% <100.00%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/wallet/mod.rs Outdated
.to_string();
let (descriptor, keymap) = descriptor.into_wallet_descriptor(secp, network_kind)?;
if !keymap.is_empty() {
return Err(DescriptorError::Miniscript(miniscript::Error::Unexpected(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are already dedicated variants for validation rules like this (HardenedDerivationXpub and ExternalAndInternalAreTheSame), would it make sense to add one here so callers can match on this condition without inspecting the message string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, after the comments from @ValuedMammal in #481, this will be removed entirely.

Comment thread src/wallet/mod.rs Outdated
assert!(result.is_ok());

// Test with empty descriptor
let public_empty = "";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test returns early at parse_descriptor before keymap.is_empty() is ever checked. It's testing parse error propagation, not the new check. Maybe clarify the comment to reflect that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, This will be removed entirely.

Copy link
Copy Markdown

@aagbotemi aagbotemi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done working on this @AmosOO7. The docs for wallet_name_from_descriptor look slightly stale.

Comment thread src/wallet/mod.rs Outdated
Err(DescriptorError::Miniscript(Unexpected(..)))
));
// Test with change descriptor containing public keys (should be ok)
let public_change_without_private = "wpkh([9a6a2580/84'/1'/0']tpubDDnGNapGEY6AZAdQbfRJgMg9fvz8pUBrLwvyvUqEgcUfgzM6zc2eVK4vY9x9L5FJWdX8WumXuLEDV5zDZnTfbn87vLe9XceCFwTu9so9Kks/1/*)";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of public_change above, as they have same descriptor string. One can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks

Comment thread src/wallet/mod.rs Outdated
@@ -2797,16 +2797,23 @@ where
T: IntoWalletDescriptor,
{
// TODO: check descriptors contains only public keys
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed now that the check is implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice catch

@AmosOO7 AmosOO7 force-pushed the add_check_for_descriptors-wallet_name_from_descriptor branch 4 times, most recently from 3a7cd0d to 11fb999 Compare May 15, 2026 11:36
…or checksums

- Update `wallet_name_from_descriptor` to compute descriptor checksum explicitly
- Remove reliance on `to_string()` implicitly containing `#checksum`
- Clarify that wallet name is defined by public descriptor checksums
- Add regression test for equivalent xpub/xprv wallet names
@AmosOO7 AmosOO7 force-pushed the add_check_for_descriptors-wallet_name_from_descriptor branch from 11fb999 to ab1d73b Compare May 15, 2026 11:54
@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet May 15, 2026
@ValuedMammal ValuedMammal added this to the Wallet 3.1.0 milestone May 15, 2026
@ValuedMammal
Copy link
Copy Markdown
Collaborator

In ab1d73b

For clarity you should have somewhere in the test the expected wallet name, for example

assert_eq!(public_result.as_ref().unwrap(), "vn4aqs37");

@AmosOO7
Copy link
Copy Markdown
Contributor Author

AmosOO7 commented May 15, 2026

In ab1d73b

For clarity you should have somewhere in the test the expected wallet name, for example

assert_eq!(public_result.as_ref().unwrap(), "vn4aqs37");

Thank you for that, I will update that now.

Extract public_result.unwrap() into a variable to avoid consuming it twice,
enabling comparison between checksums in test
@ValuedMammal
Copy link
Copy Markdown
Collaborator

Since we're touching this part of the code we should make the documentation super clear so users know what to expect

  • Deterministic calculation
  • Checksum of the parsed public descriptor
  • If present, the change descriptor checksum is appended
  • Accepts private descriptors, and produces the same name as the public form
  • Errors if descriptor parsing fails, or computing the checksum failed

@ValuedMammal
Copy link
Copy Markdown
Collaborator

We should update the PR description as well once you've settled on a direction. If you're using links in the PR description, they're not showing up well 🧐

@AmosOO7 AmosOO7 changed the title Add public-key-only validation for wallet_name_from_descriptor Fix wallet name generation to use explicit public descriptor checksum May 15, 2026
@AmosOO7
Copy link
Copy Markdown
Contributor Author

AmosOO7 commented May 15, 2026

Since we're touching this part of the code we should make the documentation super clear so users know what to expect

  • Deterministic calculation
  • Checksum of the parsed public descriptor
  • If present, the change descriptor checksum is appended
  • Accepts private descriptors, and produces the same name as the public form
  • Errors if descriptor parsing fails, or computing the checksum failed

Will push an update for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Clarify wallet_name_from_descriptor behavior and compute checksum explicitly

4 participants